//
//  Fonction.h
//  copilateur
//
//  Created by Loic Cipolla on 06/11/12.
//
//

#ifndef _Fonction_hpp
#define _Fonction_hpp

#include <iostream>
#include "Categorie.hpp"
#include "../SymbTable.hpp"
#include "../type/Type.hpp"
#include "../type/TypeInteger.hpp"
#include "../type/TypeString.hpp"
#include "../type/TypeBool.hpp"
#include "../type/TypeChar.hpp"
#include "../type/TypeReal.hpp"

using std::string;
using std::cout;
using std::endl;

class Fonction : public Categorie{
public:

    Fonction(){
        this->arite= 0;
        this->ts = new SymbTable();
        TYPE = Categorie::FONCTION;
    }
    ~Fonction(){
    }
    void setArite(int i){
        this->arite=i;
    }
    int getArite(){
        return this->arite;
    }
    
    void setTsLocale(SymbTable* t){
        this->ts=t;
    }

	void printLine(){
		cout << "Fonction ";
		
		cout << "arite : " << this->arite << ", type retour : ";
		if(typeRetour != NULL){
        if(typeRetour->CODE_TYPE == Type::TYPE_INTEGER){
            cout << "integer";
        }else if(typeRetour->CODE_TYPE == Type::TYPE_REAL ){
            cout << "real";
        }else if(typeRetour->CODE_TYPE == Type::TYPE_STRING ){
            cout << "string";
        }else if(typeRetour->CODE_TYPE == Type::TYPE_CHAR ){
            cout << "char";
        }else if(typeRetour->CODE_TYPE == Type::TYPE_BOOL ){
            cout << "boolean";
        }else{
            cout << "default type";
        }
    }else{
        cout << "NULL";
    }
	cout << endl;
	}
	void setTypeRetour(int t){
        //initType();
        switch (t) {
            case Type::TYPE_INTEGER:
                this->typeRetour = new TypeInteger();
                break;
            case Type::TYPE_REAL:
                this->typeRetour = new TypeReal();
                break;
            case Type::TYPE_BOOL:
                this->typeRetour = new TypeBool();
                break;
            case Type::TYPE_STRING:
                this->typeRetour = new TypeString();
                break;
            case Type::TYPE_CHAR:
                this->typeRetour = new TypeChar();
                break;
            default:
                break;
        }
}

private:
	Type * typeRetour;
    int arite;
    SymbTable *ts;
};

#endif /* defined(__copilateur__Fonction__) */
